$(function () {
    if(invitationKey!=null&&invitationKey!=""){
        sessionStorage.invitationKey=invitationKey;
    }
    $("body").on('click','#sendRand',function () {//发送验手机证码
        var _that = this;
        disabledSend(_that);
        var mobile = $("input[name='mobile']").val();
        sendCode(mobile,1,function () {
            $(_that).hide();
            $("#countdown").show();
            $("#countdown").text('(60s)后重新获取');
            var time = 60;
            var inter = setInterval(function () {
                time --;
                if(time<=0){
                    window.clearInterval(inter);
                    $(_that).show();
                    $("#countdown").hide();
                    relieveSend(_that);
                }else{
                    $("#countdown").text('('+time+'s)后重新获取');
                }
            },1000);
        },_that);
    }).on('click',"#registerBtn",function () {//注册
        var mobile=$('input[name="mobile"]').val();
        var mobileCode=$('input[name="mobileCode"]').val();

        var password=$('input[name="password"]').val();
        var confirmPwd=$('input[name="confirmPwd"]').val();
        if(password !=null && $.trim(password)!=''){
            var encrypt = new JSEncrypt();
            encrypt.setPublicKey(publicKey);
            password= encrypt.encrypt(password);
        }
        if(confirmPwd !=null && $.trim(confirmPwd)!=''){
            var encrypt = new JSEncrypt();
            encrypt.setPublicKey(publicKey);
            confirmPwd= encrypt.encrypt(confirmPwd);
        }
        var status=$("#noticeOfRegistration:checked").val();
        if(status==undefined||status=='undefined'){
            $.toast("请您再阅读注册协议后同意并勾选");
            return;
        }
        var obj={"mobile":mobile,
            "mobileCode":mobileCode,
            "password":password,
            "confirmPwd":confirmPwd,
            "sign":sign};
      var   invitationKeyold =   sessionStorage.invitationKey;
            if(invitationKeyold!=null&&invitationKeyold!=""){
                obj.invitationKey =invitationKeyold;
            }
        $.ajax({
            url:baseloaction+"/mobile/user/doRegister",
            data:obj,
            dataType:"json",
            type:"post",
            success:function (result) {
                if(result.success==true){
                    var url = result.url;
                    sessionStorage.invitationKey ="";
                    if(url==null || $.trim(url)==''){
                        redirectURL(baseloaction +'/mobile/uc/index');
                    }else{
                        window.location.href = baseloaction + url;
                    }
                }else{
                    sign = result.keyMap.sign;
                    publicKey = result.keyMap.publicKey;
                    $.toast(result.message);
                }
            },
            error:function (error) {
                $.toast('系统错误，注册失败');
            }
        });
    });
});
